
import sys
import os
import time

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
import random
from curl_cffi import requests
from typing import Optional
from feapder.db.redisdb import RedisDB
from feapder.network.user_pool import GuestUser
from feapder.network.user_pool import GuestUserPool
from util import MyUtils
import re
from loguru import logger

class userPool(GuestUserPool):
    def __init__(self, redis_key, **kwargs):
        super().__init__(redis_key, **kwargs)
        self._redisdb = RedisDB(
            # ip_ports="139.9.196.26:6379",
            ip_ports="127.0.0.1:6379",
            user_pass='python',
            db=0,
        )
class qccUserPool(userPool):
    def login(self) -> Optional[GuestUser]:
        logger.info("q11")
        response = requests.get("https://www.qcc.com/", MyUtils.get_proxy())
        text = response.text
        pid = re.findall("(?<=window.pid=').*?(?=')", text)
        pid=pid.pop()
        tid = re.findall("(?<=window.tid=').*?(?=')", text)
        tid=tid.pop()
        user=GuestUser(
            pid=pid,
            tid=tid,
            cookies = dict(response.cookies),
        )
        return user
if __name__ == '__main__':
    userpoll=qccUserPool("qcc:pool",min_users=5000,keep_alive=True)

    # for  i in range(100):
    #
    #     user = userpoll.get_user().to_dict()
    #     logger.success(f"{user['user_id']}")

    userpoll.run()
    # while 1:
    #     user=userpoll.get_user().to_dict()
    #     userpoll.del_user(user['user_id'])
    #     logger.success(f"删除{user['user_id']}")
    #     time.sleep(0.1)
    # # userpoll.run()
    # for i in  range(50):
    #     print(user)
    #
    #     time.sleep(5)
